package xyz.xtt.third.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.asset.client.AssetClient;
import xyz.xtt.asset.client.request.ThirdOrderRequest;
import xyz.xtt.asset.client.response.AssetAllInfoResponse;
import xyz.xtt.asset.client.response.MintResponse;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.pay.client.PayClient;
import xyz.xtt.third.service.IInnserService;
import xyz.xtt.user.client.UserClient;
import xyz.xtt.user.client.request.UserRegRequest;
import xyz.xtt.user.client.response.UserInfoResponse;
import xyz.xtt.user.client.response.UserRegResponse;

@Slf4j
@Service
public class InnserServiceImpl implements IInnserService {
	@Autowired
	private PayClient payClient;
	@Autowired
	private AssetClient assetClient;
	@Autowired
	private UserClient userClient;

	@Override
	public UserInfoResponse infoWithPhone(String phone) {
		ApiResult<UserInfoResponse> response = userClient.infoWithPhone(phone);
		log.info("userClient infoWithPhone response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}

	@Override
	public UserRegResponse register(UserRegRequest userRegRequest) {
		ApiResult<UserRegResponse> response = userClient.register(userRegRequest);
		log.info("userClient register response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}

	@Override
	public AssetAllInfoResponse infoGoodsId(String goodsId) {
		ApiResult<AssetAllInfoResponse> response = assetClient.infoGoodsId(goodsId);
		log.info("userClient extInfoWithAssetId response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}

	@Override
	public MintResponse thirdOrder(ThirdOrderRequest payOrderDto) {
		ApiResult<MintResponse> response = assetClient.thirdOrder(payOrderDto);
		log.info("userClient thirdOrder response:{}", JSONUtil.toJsonStr(response));
		return ApiResult.convert(response, null);
	}
}
